package com.chuanc.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chuanc.R;
import com.chuanc.adapter.MainFragmentAdapter;
import com.chuanc.adapter.MainFragmentItem;

import java.util.ArrayList;


/**
 * Created by Angel on 2017/10/17.
 */

public class MainFragment extends AttachFragment {

    private MainFragmentAdapter mAdapter;
    private RecyclerView recyclerView;
    private LinearLayoutManager layoutManager;
    private ArrayList<MainFragmentItem> mList = new ArrayList<>();


    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_main, container, false);
        recyclerView= (RecyclerView) view.findViewById(R.id.recyclerview);
        initItemData();
        layoutManager = new LinearLayoutManager(mContext);
        recyclerView.setLayoutManager(layoutManager);
        mAdapter = new MainFragmentAdapter(mList);
        recyclerView.setAdapter(mAdapter);
        return view;
    }

    public void initItemData(){
        setInfo(mContext.getResources().getString(R.string.local_music), 30, R.drawable.music_icn_local, 0);
        setInfo(mContext.getResources().getString(R.string.recent_play), 49, R.drawable.music_icn_recent, 1);
        setInfo(mContext.getResources().getString(R.string.local_manage), 60, R.drawable.music_icn_dld, 2);
        setInfo(mContext.getResources().getString(R.string.my_artist), 3, R.drawable.music_icn_artist, 3);
    }

    private void setInfo(String title, int count, int id, int i) {
        MainFragmentItem information = new MainFragmentItem();
        information.title = title;
        information.count = count;
        information.avatar = id;
        if (mList.size() < 4) {
            mList.add(new MainFragmentItem());
        }
        mList.set(i, information); //将新的info对象加入到信息列表中
    }

}
